Skip to main content

BodyDef Class

Description:

  A class for creating BodyDef and FixtureDef.

polygon

Type: Function.

Description:

  Creates a polygon fixture definition with the specified dimensions.

Signature:

polygon: function(self: BodyDefClass,
width: number,
height: number,
density?: number --[[0.0]],
friction?: number --[[0.4]],
restitution?: number --[[0.0]]): FixtureDef

Parameters:

ParameterTypeDescription
widthnumberThe width of the polygon.
heightnumberThe height of the polygon.
densitynumber[optional] The density of the polygon (default is 0.0).
frictionnumber[optional] The friction of the polygon (default is 0.4, should be 0.0 to 1.0).
restitutionnumber[optional] The restitution of the polygon (default is 0.0, should be 0.0 to 1.0).

Returns:

Return TypeDescription
FixtureDefA FixtureDef object for the created polygon fixture.

polygon

Type: Function.

Description:

  Creates a polygon fixture definition with the specified dimensions and center position.

Signature:

polygon: function(self: BodyDefClass,
center: Vec2,
width: number,
height: number,
angle?: number --[[0.0]],
density?: number --[[0.0]],
friction?: number --[[0.4]],
restitution?: number --[[0.0]]): FixtureDef

Parameters:

ParameterTypeDescription
centerVec2The center position of the polygon.
widthnumberThe width of the polygon.
heightnumberThe height of the polygon.
anglenumber[optional] The angle of the polygon in radians (default is 0.0).
densitynumber[optional] The density of the polygon (default is 0.0).
frictionnumber[optional] The friction of the polygon (default is 0.4, should be 0.0 to 1.0).
restitutionnumber[optional] The restitution of the polygon (default is 0.0, should be 0.0 to 1.0).

Returns:

Return TypeDescription
FixtureDefA FixtureDef object for the created polygon fixture.

polygon

Type: Function.

Description:

  Creates a polygon fixture definition with the specified vertices.

Signature:

polygon: function(self: BodyDefClass,
vertices: {Vec2},
density?: number --[[0.0]],
friction?: number --[[0.4]],
restitution?: number --[[0.0]]): FixtureDef

Parameters:

ParameterTypeDescription
vertices{Vec2}A table containing the vertices of the polygon.
densitynumber[optional] The density of the polygon (default is 0.0).
frictionnumber[optional] The friction of the polygon (default is 0.4, should be 0.0 to 1.0).
restitutionnumber[optional] The restitution of the polygon (default is 0.0, should be 0.0 to 1.0).

Returns:

Return TypeDescription
FixtureDefA FixtureDef object for the created polygon fixture.

multi

Type: Function.

Description:

  Create a concave shape definition made of multiple convex shapes.

Signature:

multi: function(self: BodyDefClass,
vertices: {Vec2},
density?: number --[[0.0]],
friction?: number --[[0.4]],
restitution?: number --[[0.0]]): FixtureDef

Parameters:

ParameterTypeDescription
vertices{Vec2}A table containing the vertices of each convex shape that makes up the concave shape.Each convex shape in the vertices table should ends with a Vec2(0.0, 0.0) as seperator.
densitynumberThe density of the shape (optional, default 0.0).
frictionnumberThe friction coefficient of the shape (optional, default 0.4, should be 0.0 to 1.0).
restitutionnumberThe restitution (elasticity) of the shape (optional, default 0.0, should be 0.0 to 1.0).

Returns:

Return TypeDescription
FixtureDefThe resulting fixture definition.

disk

Type: Function.

Description:

  Create a Disk-shape fixture definition.

Signature:

disk: function(self: BodyDefClass,
center: Vec2,
radius: number,
density?: number --[[0.0]],
friction?: number --[[0.4]],
restitution?: number --[[0.0]]): FixtureDef

Parameters:

ParameterTypeDescription
centerVec2The center of the circle.
radiusnumberThe radius of the circle.
densitynumberThe density of the circle (optional, default 0.0).
frictionnumberThe friction coefficient of the circle (optional, default 0.4, should be 0.0 to 1.0).
restitutionnumberThe restitution (elasticity) of the circle (optional, default 0.0, should be 0.0 to 1.0).

Returns:

Return TypeDescription
FixtureDefThe resulting fixture definition.

disk

Type: Function.

Description:

  Create a Disk-shape fixture definition with center at origin.

Signature:

disk: function(self: BodyDefClass,
radius: number,
density?: number --[[0.0]],
friction?: number --[[0.4]],
restitution?: number --[[0.0]]): FixtureDef

Parameters:

ParameterTypeDescription
radiusnumberThe radius of the circle.
densitynumberThe density of the circle (optional, default 0.0).
frictionnumberThe friction coefficient of the circle (optional, default 0.4, should be 0.0 to 1.0).
restitutionnumberThe restitution (elasticity) of the circle (optional, default 0.0, should be 0.0 to 1.0).

Returns:

Return TypeDescription
FixtureDefThe resulting fixture definition.

chain

Type: Function.

Description:

  Create a Chain-shape fixture definition. This fixture is a free form sequence of line segments that has two-sided collision.

Signature:

chain: function(self: BodyDefClass,
vertices: {Vec2},
friction?: number --[[0.4]],
restitution?: number --[[0.0]]): FixtureDef

Parameters:

ParameterTypeDescription
vertices{Vec2}The vertices of the chain.
frictionnumberThe friction coefficient of the chain (optional, default 0.4, should be 0.0 to 1.0).
restitutionnumberThe restitution (elasticity) of the chain (optional, default 0.0, should be 0.0 to 1.0).

Returns:

Return TypeDescription
FixtureDefThe resulting fixture definition.

__call

Type: Metamethod.

Description:

  Create a new instance of BodyDef class.

Signature:

metamethod __call: function(self: BodyDefClass): BodyDef

Returns:

Return TypeDescription
BodyDefa new BodyDef object.